package com.hainatong.shiphelper.mainhome;

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import com.base.common.app.LoginUtils;
import com.base.common.utils.LogUtil;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.gyf.immersionbar.BarHide;
import com.gyf.immersionbar.ImmersionBar;
import com.hainatong.shiphelper.GlobalConfig;
import com.hainatong.shiphelper.R;
import com.hainatong.shiphelper.api.PublicValues;
import com.hainatong.shiphelper.databinding.ActivitySplashViewBinding;
import com.hainatong.shiphelper.login.view.LoginActivity;
import com.hainatong.mvvmbase.base.BaseMvvmActivity;
import com.hainatong.mvvmbase.base.NoViewModel;

public class SplashActivity extends BaseMvvmActivity<ActivitySplashViewBinding , NoViewModel>
{
    private Animation alphaAnim;
    @Override
    protected int getLayoutId()
    {
        return R.layout.activity_splash_view;
    }

    @Override
    protected int getBindingVariable() {
        return 0;
    }

    @Override
    protected void initView()
    {
        //getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        ImmersionBar.with(this)
                    .hideBar(BarHide.FLAG_HIDE_BAR)
                    .init();


        alphaAnim = AnimationUtils.loadAnimation(this,R.anim.anim_launch_item_scale_in);

        alphaAnim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation)
            {
              boolean isAvailable =  NetworkUtils.isAvailableByPing("192.168.0.88");
              LogUtils.e( "192.168.0.88 地址 " +(isAvailable?"可以访问":"不能访问")  );
            }

            @Override
            public void onAnimationEnd(Animation animation)
            {
                // 如果用户登录了

                Boolean isLogin = LoginUtils.isLogin();

                //String authToken = SPUtils.getInstance(Constants.CONFIG).getString("Token","");

                if (isLogin)
                {
                    GlobalConfig.getInstance().setToken( LoginUtils.getToken() );
                    LogUtil.e( LoginUtils.getToken()  );
                    GlobalConfig.getInstance().setUserInfo( PublicValues.getUserInfo() );
                    MainHomeActivity.start(SplashActivity.this);
                }
                else
                {
                    LoginActivity.start(SplashActivity.this);
                }
                SplashActivity.this.finish();
            }

            @Override
            public void onAnimationRepeat(Animation animation)
            {

            }
        });
        viewDataBinding.applogo.setVisibility(View.VISIBLE);
        viewDataBinding.applogo.startAnimation(alphaAnim);

    }

    @Override
    protected void initData()
    {

    }

    @Override
    protected void onRetryBtnClick()
    {

    }
}
